﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


/// <summary>
/// Summary description for Global
/// </summary>
public class Global
{
    public static string CONNECTION_STRING = ConfigurationManager.ConnectionStrings["ConStr"].ToString();
    public const string SESSION_ERROR = "error";
    public const string SESSION_LOGGED_USER = "User";
    public const string SESSION_LOGGED_ADMIN = "Admin";
    public const string SESSION_ADMIN_USER = "Admin";
    public const string ERROR_PAGE_ADMIN = "~/Admin/ErrorPage.aspx";
    public const string ERROR_PAGE = "~/Error.aspx";
    public const string SESSION_CART = "UserCart";
    public const string SESSION_SHIPTO = "SHIPTO";
    public const string SESSION_TOTAL = "0.0";


    #region "Email"
   
    public const string CONTACT_US = "~/emailTemplates/ContactUs.htm";
    public const string CONTACT_US_THANK_YOU = "~/emailTemplates/ContactUsThankyou.htm";


    //public static string CONTACT_EMAIL_ADDRESS = ConfigurationManager.AppSettings["ContactsEmail"].ToString();
    //public static string WEBMASTER_EMAIL_ADDRESS = ConfigurationManager.AppSettings["WebmasterEmail"].ToString();
    //public static string EMAIL_PICKUP_FOLDER_LOCATION = ConfigurationManager.AppSettings["EmailPickupFolderLocation"].ToString();
    //public static string ENQUIRY_EMAIL_ADDRESS = ConfigurationManager.AppSettings["EnquiryEmail"].ToString();
    //public static string SALES_EMAIL_ADDRESS = ConfigurationManager.AppSettings["SalesEmail"].ToString();
    //public static string IS_ASYN = ConfigurationManager.AppSettings["IsAsyn"].ToString();

    #endregion

    public Global()
    {
        
        //
        // TODO: Add constructor logic here
        //
    }

    public static int ConvertToInt(string interger)
    {
        int i = 0;
        Int32.TryParse(interger, out i);

        return i;
    }

    public static string FixStringNull(object dbvalue)
    {
        if (dbvalue == null)
            return "";
        else
            return (string)dbvalue;
    }
    public static string randomString(int lenght)
    {
        string strBase = "ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwyz0123456789";
        System.Text.StringBuilder strResult = new System.Text.StringBuilder();
        Random rand = new Random(DateTime.Now.Millisecond);
        for (int i = 0; i < lenght; i++)
            strResult.Append(strBase[rand.Next(0, strBase.Length - 1)]);
        return strResult.ToString();
    }
    public static string GetPageName(string Url)
    {
        int i = Url.LastIndexOf(".aspx");
        string PageName = "";
        if (i > 0)
        {
            PageName = Url.Substring(0, i);
            i = PageName.LastIndexOf("/");
            PageName = Url.Substring(i + 1);
        }
        return PageName;
    }

    public static DateTime ConvertToDate(string strDate)
    {
        string[] str = strDate.Split(new char[] { '/', '-' });
        if (str.Length == 3)
        {
            return new DateTime(Convert.ToInt32(str[2].Substring(0, 4)),
                        Convert.ToInt32(str[1]),
                        Convert.ToInt32(str[0]));
        }
        else
            return DateTime.Now;
    }

    public static string ConvertToDate2(string strDate)
    {
        string[] str = strDate.Split(new char[] { '/', '-' });
        if (str.Length == 3)
        {
            return new DateTime(Convert.ToInt32(str[2].Substring(0, 4)),
                        Convert.ToInt32(str[1]),
                        Convert.ToInt32(str[0])).ToString("yyyyMMdd");
        }
        else
            return "";
    }
}
